package JavaBean;

import java.sql.*;


public class DbConnect {
	public static Connection getDBconnection(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url1 = "jdbc:mysql://localhost:3306/user";
			String url2 = "?user=root&password=123456";
			String url3 = "&useUnicode=true&characterEncoding=UTF-8";
			String url = url1 + url2 + url3;
			Connection con =  DriverManager.getConnection(url);
			return con;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public static void closeDB(java.sql.Connection con, PreparedStatement pstm, ResultSet rs){
		try{
			if(rs!=null){
				rs.close();
			}if(pstm!=null){
				pstm.close();
			}if(con!=null){
				con.close();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
